package com.ada.myblog.controller;

import com.ada.myblog.pojo.Article;
import com.ada.myblog.repository.ArticleRepository;
import com.ada.myblog.service.Impl.ArticleService.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class IndexController {

    @Autowired
    ArticleService articleService;
    //@PathVariable 获取对应参数
    @RequestMapping("/index/{page}")
    public String toIndexPage(@PathVariable("page") String page,Model model){
        Pageable pageable =  PageRequest.of(Integer.parseInt(page)-1,3);
        model.addAttribute("articleList",articleService.findAll(pageable));
        return "index";
    }
}
